import java.util.Scanner;

public class ArraySumMax {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);

        System.out.print("请输入数组的大小: ");
        int size=scanner.nextInt();
        int[] array=new int[size];

        System.out.println("请输入数组的元素: ");
        for (int i=0; i<size; i++) {
            array[i]=scanner.nextInt();
        }

        int maxArraySum=Integer.MIN_VALUE;
        for(int i=0; i<size; i++){
            int currentSum=0;
            for(int j=i; j<size; j++){
                currentSum+=array[j];
                if(currentSum>maxArraySum) {
                    maxArraySum = currentSum;
                }
            }
        }

        System.out.println("子数组的最大和是: "+maxArraySum);
        scanner.close();
    }
}
